// merge collections: col2, col2
final = col1.merge(col2)

// find the native resolution of raster image
// https://developers.google.com/earth-engine/tutorials/tutorial_api_03#digression:-scale-in-earth-engine
var scale = srtm.projectin().nominalSacle();
print('SRTM scale in meters', sacle);

// calculate NDVI
// the infra-red and red band in landsat 8 is Band 5 and 4, which might be other band in a another remote sensing product
// https://developers.google.com/earth-engine/tutorials/tutorial_api_07#digression:-simple-cloud-masking-for-landsat
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI')

// use mask to remove impact of cloud
var cloudlessNDVI = l8.map(function (image) {
  // Get a cloud score in [0, 100].
  var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');

  // Create a mask of cloudy pixels from an arbitrary threshold.
  var mask = cloud.lte(20);

  // Compute NDVI.
  var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');

  // Return the masked image with an NDVI band.
  return image.addBands(ndvi).updateMask(mask);
});

print(ui.Chart.image.series({
  imageCollection: cloudlessNDVI.select('NDVI'),
  region: roi,
  reducer: ee.Reducer.first(),
  scale: 30
}).setOptions({ title: 'Cloud-masked NDVI over time' }));


var in_getBandValue = function (image, feature) {
  var vFeatures = ee.FeatureCollection([feature])
  var vBands = ee.Image(image).sampleRegions(vFeatures)
  return ee.Feature(vBands.first()).set('isNull',false)
}
